const jwt = require('jsonwebtoken')
const { createUser, getUserInfo } = require('../service/user.service')
const { userRegisterError } = require('../constants/err.type')

class UserController{
    async login(ctx, next) {
        const { user_name } = ctx.request.body
        try{
            const {password, ...resUser} = ctx.res
            console.log(ctx.res);
        }catch(err){

        }

        ctx.body = user_name
    }

    async register(ctx, next) {
        const {user_name, password} = ctx.request.body

        try{
            const res = await createUser({user_name, password})
            ctx.body = {
                code: 0,
                message: "用户注册成功",
                result: res
            }
        }catch(err){
            console.error('用户注册失败', err)
            ctx.app.emit("error", userRegisterError, ctx)
        }
    }
}

module.exports = new UserController()